package com.yootk.config;

import com.yootk.condition.BookCondition;
import com.yootk.condition.EduCondition;
import com.yootk.di.config.MessageConfig;
import com.yootk.vo.Dept;
import com.yootk.vo.Emp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

//@Configuration
public class YootkConfig2 {
    private static final Logger LOGGER = LoggerFactory.getLogger(YootkConfig2.class);

    @Bean
    @DependsOn("dept")  // 该操作需要等待dept的Bean注册完成
    public Emp emp() {
        LOGGER.info("【Emp】雇员Bean实例化。");
        Emp emp = new Emp();
        return emp;
    }

    @Bean
    public Dept dept() {
        LOGGER.info("【Dept】部门Bean实例化。");
        Dept dept = new Dept();
        return dept;
    }

    @Bean("book")
    @Conditional({BookCondition.class})     // 定义处理条件
    public MessageConfig book() {
        MessageConfig config = new MessageConfig();
        config.setHost("www.yootk.com");
        config.setPort(9090);
        config.setEnable(true);
        return config;
    }

    @Bean("edu")
    @Conditional({EduCondition.class})      // 定义处理条件
    public MessageConfig edu() {
        MessageConfig config = new MessageConfig();
        config.setHost("edu.yootk.com");
        config.setPort(7979);
        config.setEnable(true);
        return config;
    }
}
